package com.ykht.proj.coupon.controller.b;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ykht.proj.common.core.util.R;
import com.ykht.proj.common.security.util.SecurityUtils;
import com.ykht.proj.coupon.Enum.LookRoleTypeEnum;
import com.ykht.proj.coupon.entity.CnBrand;
import com.ykht.proj.coupon.entity.FxCmsInfo;
import com.ykht.proj.coupon.service.CnUserExtService;
import com.ykht.proj.coupon.service.FxCmsInfoService;
import com.ykht.proj.coupon.vo.CmsInfoTemplate;
import com.ykht.proj.coupon.vo.FxCmsInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;


/**
 * @Author: lazyBoy
 * @Date: 2021/2/23 15:51
 */
@RestController
@AllArgsConstructor
@RequestMapping("/b/fxCmsInfo")
@Api(value = "/b/fxCmsInfo", tags = "文章内容管理")
@Slf4j
public class BnCmsInfoController {
	private final FxCmsInfoService fxCmsInfoService;
	private final CnUserExtService cnUserExtService;

	@ApiOperation(value = "分页查询", notes = "分页查询")
	@GetMapping("/page")
	public R<Page<FxCmsInfo>> getFxCmsInfoPage(Page<FxCmsInfo> page, FxCmsInfo fxCmsInfo) {
		CnBrand cnBrand = new CnBrand().selectById(SecurityUtils.getSjId());
		page = fxCmsInfoService.page(page, Wrappers.lambdaQuery(FxCmsInfo.class).eq(FxCmsInfo::getBrandId, cnBrand.getId()).eq(FxCmsInfo::getStatus, fxCmsInfo.getStatus()).orderByAsc(FxCmsInfo::getPushStatus).orderByDesc(FxCmsInfo::getCreateTime));
		return R.ok(page);
	}

	@ApiOperation(value = "推送", notes = "推送")
	@PutMapping()
	public R setFxCmsInfoStatus(@RequestBody FxCmsInfo fxCmsInfo) {
		fxCmsInfoService.updateValueById(fxCmsInfo);
		return R.ok();
	}

	@ApiOperation(value = "b端文章详情（分享进来的文章需要传waiterId获取门店电话）", notes = "文章详情")
	@GetMapping("/{id}")
	public R<CmsInfoTemplate> getById(@PathVariable("id") Long id) {
		log.info("->文章详情：{}", id);
		return fxCmsInfoService.getCmsInfoTemplateById_B(id);
	}

}
